class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int i = 0, sum = 0, minv = INT_MAX;
        for (int j = 0; j < nums.size(); ++j)
        {
            sum += nums[j];
            while (sum >= target)
            {
                minv = min(minv, j - i + 1);
                sum -= nums[i++];
            }
        }
        return minv == INT_MAX ? 0 : minv;
    }
};